//
//  NWHomeCellBottom.swift
//  微博01
//
//  Created by 牛威 on 15/12/11.
//  Copyright © 2015年 牛威. All rights reserved.
//

import UIKit



class NWHomeCellBottom: UIView {
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor  = UIColor(white: 0.95, alpha: 1)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

   
/// 懒加载 
    //转发按钮  修正1 设置button的文字和图片离得太近 --->在设置文字的时候前加上一个空格可以改进
    
    private lazy var retweetedBtn : UIButton = UIButton(title: " 转发", imageName: "timeline_icon_retweet", color: UIColor.darkGrayColor(), fontSize: 12)
    
    //评论按钮
    
    private lazy var commentBtn : UIButton = UIButton(title: " 评论", imageName: "timeline_icon_comment", color: UIColor.darkGrayColor(), fontSize: 12)

    //点赞按钮
    
    private lazy var likeBtn : UIButton = UIButton(title: " 点赞", imageName: "timeline_icon_unlike", color: UIColor.darkGrayColor(), fontSize: 12)


}

extension NWHomeCellBottom {


    private func setupUI(){
    
        //添加控件
        
        addSubview(retweetedBtn)
        addSubview(commentBtn)
        addSubview(likeBtn)
        
        //设置约束
        
            /// 转发
        
           retweetedBtn.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
        }
                    
            /// 评论约束
        
        commentBtn.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(retweetedBtn.snp_top)
            make.left.equalTo(retweetedBtn.snp_right)
            make.width.equalTo(retweetedBtn.snp_width)
            make.height.equalTo(retweetedBtn.snp_height)
        }
        
            /// 点赞约束
        
        likeBtn.snp_makeConstraints { (make) -> Void in
           
            make.top.equalTo(commentBtn.snp_top)
            make.left.equalTo(commentBtn.snp_right)
            make.width.equalTo(commentBtn.snp_width)
            make.height.equalTo(commentBtn.snp_height)
            
            make.right.equalTo(self.snp_right)

        }
        
        //添加分割线
        
        let width = 0.5 //一个像素点 在sb中是无法设置的
        let scale = 0.4
        
        let sep1 = sepView()
        let sep2 = sepView()
        
        addSubview(sep1)
        addSubview(sep2)
        
        //设置分割线1的约束
        
        sep1.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(retweetedBtn.snp_right)
            make.centerY.equalTo(retweetedBtn.snp_centerY)
            make.width.equalTo(width)
            make.height.equalTo(retweetedBtn.snp_height).multipliedBy(scale)
        }
        
        //设置分割线2
        sep2.snp_makeConstraints { (make) -> Void in
            
            
            make.left.equalTo(commentBtn.snp_right)
            make.centerY.equalTo(commentBtn.snp_centerY)
            make.width.equalTo(width)
            make.height.equalTo(commentBtn.snp_height).multipliedBy(scale)

        }
        
    
    }
    
    /// 此处如果修改为计算型属性 会让代码的阅读变得困难 所以建议用函数来写
    ///
    private func sepView()->UIView{
    
        let v = UIView() //uiview是最轻量级的控件 因为大部分控件都继承自它
        
        v.backgroundColor = UIColor.darkGrayColor()
        return v
    
    
    }
    
    //计算型属性的对比2
    
//    private var sepView1:UIView {
//        
//        let v = UIView() //uiview是最轻量级的控件 因为大部分控件都继承自它
//        
//        v.backgroundColor = UIColor.darkGrayColor()
//        return v
//        
//        
//    }




}
